package com.codingfuture.erp_system.web.controller;

import com.codingfuture.erp_system.dto.MenuDto;
import com.codingfuture.erp_system.entity.RoleMenu;
import com.codingfuture.erp_system.service.MenuService;
import com.codingfuture.erp_system.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@RequestMapping("/v2/menu")
@RestController
public class MenuController {

    @Autowired
    private MenuService menuService;

    @GetMapping("/select")
    public Result<?> findAll(HttpSession session) {
        Object uuid = session.getAttribute("uuid");
        List<RoleMenu> list = menuService.findAll(uuid);
        if (list != null && list.size() != 0) {
            List<MenuDto> menuDtoList = menuService.findByAll(list);
            if (menuDtoList.size() != 0) {
                return Result.ok(menuDtoList);
            }
        }
        return Result.error(201, "该用户没有权限");
    }
}
